<?php session_start();?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php 
	$username = trim($_POST['username']);
	$password = md5(trim($_POST['password']));
	$confirm_code = $_POST['confirm_code'];
	require '../public/conn.php';
	$result = mysql_query("SELECT * FROM users WHERE username = '$username'");
	$isUserExist= mysql_fetch_array($result);
	if($isUserExist){ //用户已存在
		mysql_close($con);
		header("location:../face/register-face.php?isUserExist=true");
	}else if($confirm_code != $_SESSION['confirm_code']){//验证码不对
		mysql_close($con);
		header("location:../face/register-face.php?FalseConfirmCode=true");
	}else{
		//满足注册条件，注册
		mysql_query("INSERT INTO users (username,password)
		VALUES ('$username','$password')");
		$_SESSION['username'] = $username;
		header("location:../home/home.php");
	}
	echo $isUserExist;
	mysql_close($con);
?>
</body>
</html>